﻿//Write a program that finds the most frequent number in an array.
//Example: {4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3} -> 4 (5 times)

using System;

public class MostFrequentNumber
{
    public static void Main()
    {
        Console.Write("Enter length of array L = ");
        int length = int.Parse(Console.ReadLine());
        int[] array = new int[length];
        Console.WriteLine("Enter {0} elements", length);
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = int.Parse(Console.ReadLine());
        }
        for (int i = 0; i < array.Length; i++)
        {
            if (i == 0)
            {
                Console.Write("{{{0}, ", array[i]);
            }
            else if (i == array.Length - 1)
            {
                Console.Write("{0}}}\n", array[i]);
            }
            else
            {
                Console.Write("{0}, ", array[i]);
            }
        }
        int numberCount = 0;
        int number = 0;
        int count = 0;
        do
        {
            int tempCount = 0;
            for (int i = count; i < array.Length; i++)
            {
                if (array[count] == array[i])
                {
                    tempCount++;                    
                }                
            }
            if (numberCount < tempCount)
            {
                numberCount = tempCount;
                number = array[count];
            }
            count++;
        } while (count < array.Length);

        Console.WriteLine("Most frequent number -> {0} ({1} times)", number, numberCount);
    }
}